package com.binhthuan.catechist.client;

import com.binhthuan.catechist.client.content.manage.ManageArea;
import com.binhthuan.catechist.client.content.manage.ManageCourse;
import com.binhthuan.catechist.client.content.manage.ManageGrade;
import com.binhthuan.catechist.client.content.manage.ManageSchoolDate;
import com.binhthuan.catechist.client.content.manage.ManageSchoolYear;
import com.binhthuan.catechist.client.content.manage.ManageShift;
import com.binhthuan.catechist.client.content.manage.ManageStatus;
import com.binhthuan.catechist.client.content.manage.ManageVenue;
import com.binhthuan.catechist.client.content.training.AttendancePage;
import com.binhthuan.catechist.client.content.training.TraineeRegisterPage;
import com.binhthuan.catechist.client.content.training.SchedulePage;
import com.binhthuan.catechist.client.content.training.TraineeListPage;
import com.binhthuan.catechist.client.content.training.TrainerAssignmentPage;
import com.binhthuan.catechist.client.content.training.TrainerListPage;
import com.binhthuan.catechist.client.menu.StackMenu;
import com.binhthuan.catechist.client.menu.StackMenuItem;
import com.binhthuan.catechist.client.menu.StackMenuSection;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.SectionStackSection;

public class NavigationMenu extends StackMenu {

    /**
     * 
     */
    public NavigationMenu() {
        super();
        addSections(getTrainingSection(), getSearchSection(), getCalendarSection(), getManageSection());
    }

    /**
     * @param sections
     */
    public NavigationMenu(StackMenuSection... sections) {
        super(sections);
    }

    public StackMenuSection getSearchSection() {
        StackMenuSection section = new StackMenuSection(ECApplication.getConstants().search(), (StackMenuItem) null);
        section.setTitle("</span>" + Canvas.imgHTML(ECIcons.getIcon("trainee.png")) + ECApplication.getConstants().search() + "</span>");
        return section;
    }

    public StackMenuSection getTrainingSection() {
        StackMenuSection section = new StackMenuSection("Training", ECIcons.getIcon("trainee.png"));
        section.addMenuItem(new StackMenuItem(TraineeListPage.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(AttendancePage.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(SchedulePage.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(TraineeRegisterPage.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(TrainerListPage.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(TrainerAssignmentPage.Factory.getInstance()));

        return section;
    }

    public StackMenuSection getCalendarSection() {
        return new StackMenuSection(ECApplication.getConstants().schedule(), (StackMenuItem) null);
    }

    public StackMenuSection getManageSection() {
        StackMenuSection section = new StackMenuSection("Manage", ECIcons.getIcon("library.png"));
        section.addMenuItem(new StackMenuItem(ManageSchoolYear.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageSchoolDate.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageShift.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageArea.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageStatus.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageVenue.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageCourse.Factory.getInstance()));
        section.addMenuItem(new StackMenuItem(ManageGrade.Factory.getInstance()));
        return section;
    }

    public void selectMenuItem(String name) {
        SectionStackSection[] sections = getSections();
        StackMenuItem selectedItem = null;

        for (int i = 0; i < sections.length; i++) {
            selectedItem = ((StackMenuSection) sections[i]).getMenuItem(name);
            if (selectedItem != null) {
                expandSection(i);
                ((StackMenuSection) sections[i]).selectMenuItem(selectedItem);
                break;
            }
        }
    }
}
